<?php

class Connexion extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function index() {
        $data["erreur"] = '';
        $this->template->load('template', 'Page/loginform', $data);
    }
    
    public function login(){
        $auth = $this->user_model->authentification($this->input->post('username'),$this->input->post('password'));
        if($auth != "0"){
            $newdata = array(
                'username' => $auth->username,
                'password' => $auth->password 
            );
            $this->session->set_userdata($newdata);
            redirect('admin');
            }
        else {
            $data["erreur"] = "Erreur identifiant et/ou mot de passe";
            $this->template->load('template', 'Page/loginform',$data);
        }
    }

    
    public function deco(){
        $this->session->unset_userdata('username');
        redirect(connexion);
    }
}

?>
